package com.base.util.javautils.log;

import com.orhanobut.logger.LogLevel;
import com.orhanobut.logger.Settings;

/**
 * Created by gj on 16-1-19.
 */
public class LogSettings {

    public static LogSettings toDefaultSettings(ILogPrinter logPrinter) {
        return new LogSettings(logPrinter).toDefaultSettings();
    }

    private final LogPrinter mPrinter;
    private final Settings mResetSettings;
    private final Settings mSettings;

    public LogSettings(ILogPrinter logPrinter) {
        mPrinter = (LogPrinter) logPrinter;
        mSettings = mPrinter.getSettings();
        mResetSettings = new Settings();
        copySettingsAToB(mSettings, mResetSettings);
    }

    private void copySettingsAToB(Settings a, Settings b) {
        b.methodCount(a.getMethodCount());
        b.methodOffset(a.getMethodOffset());
        b.logLevel(a.getLogLevel());
        b.logTool(a.getLogTool());
    }

    public ILogPrinter getLogPrinter() {
        return mPrinter;
    }

    public LogSettings reset() {
        copySettingsAToB(mResetSettings, mSettings);
        return this;
    }

    public LogSettings setMethodCount(int methodCount) {
        mSettings.methodCount(methodCount);
        return this;
    }

    public LogSettings setMethodOffset(int methodOffset) {
        mSettings.methodOffset(methodOffset);
        return this;
    }

    public LogSettings isShowLog(boolean isShow) {
        mSettings.logLevel(isShow ? LogLevel.FULL : LogLevel.NONE);
        return this;
    }

    public LogSettings toDefaultSettings() {
        mSettings.methodOffset(LogConfig.LOG_METHOD_OFFSET)
                .methodCount(LogConfig.LOG_METHOD_COUNT)
                .logLevel(LogConfig.LOG_ON_DEFAULT ? LogLevel.FULL : LogLevel.NONE);
        if (!LogConfig.LOG_SHOW_THREAD_INFO) {
            mSettings.hideThreadInfo();
        }
        return this;
    }

}
